/**
 * @description: get value
 * @param {type: String}
 * @return: [Object,String,null]
 */
export function getLocalStorage(key: string): any {
  let storageData = localStorage.getItem(key);
  if (storageData) {
    let storage;
    try {
      storage = JSON.parse(storageData);
    } catch (err) {
      storage = storageData;
    }
    return storage;
  }
  return storageData;
}

/**
 * @description: set value
 * @param {[key,data]}
 * @return:void
 */
export function setLocalStorage(key: string, data: any) {
  typeof data === "string" ? localStorage.setItem(key, data) : localStorage.setItem(key, JSON.stringify(data));
}

/**
 * @description: remove
 * @param { arguments }
 * @return: [Array,undefined]
 */
export function removeLocalStorageKey(...args: string[]) {
  let errArgs: string[] = [];
  args.forEach((item) => {
    typeof item === "string" ? localStorage.removeItem(item) : errArgs.push(item);
  });
  return errArgs.length ? { errMsg: "error param", errKey: errArgs } : undefined;
}
